package com.xinfan.mhl.service;

import com.xinfan.mhl.dao.DiningTableDao;
import com.xinfan.mhl.domain.DiningTable;

import java.util.List;

/**
 * @Author zhangxin
 * @Date 2022/6/23 9:45
 * @Version 1.0
 */
public class DiningTableService {
    private DiningTableDao diningTableDao = new DiningTableDao();

    public List<DiningTable> getDiningTables() {
        return diningTableDao.selectMany("select * from dinningTable",DiningTable.class);
    }

    public boolean orderTable(String orderName,String orderTel,int id) {
        int update = diningTableDao.update("update dinningTable set orderName = ?,orderTel = ?,state = '预定' where id = ?",
                orderName, orderTel, id);
        return update>0;
    }

    public DiningTable isUsed(int id) {
        return diningTableDao.selectOne("select * from dinningTable where id = ?", DiningTable.class, id);
    }

    /**
     * @Description 修改餐桌状态为就餐中
     * @Param [tableId]
     * @return boolean
     * @Author zhangxin
     * @Date 2022/6/24 13:59
     * @Version 1.0
     **/
    public boolean useTable(int tableId) {
        int update = diningTableDao.update("update dinningTable set state = '就餐中' where id = ?", tableId);
        return update>0;
    }

    /**
     * @Description 结账清空餐桌状态
     * @Param [tableId]
     * @return boolean
     * @Author zhangxin
     * @Date 2022/6/24 14:00
     * @Version 1.0
     **/
    public boolean cleanTable(int tableId) {
        int update = diningTableDao.update("update dinningTable set state = '空',orderName = '',orderTel = '' where id = ?", tableId);
        return update>0;
    }
}
